/**
 * 双击node节点，弹出节点详情
 */
import G6 from '@antv/g6';
import * as events from '../../../utils/event/componentEvent';
import { NODE } from '../utils/constants';

G6.registerBehavior('dbclick-node', {
  getEvents() {
    return {
      'node:dblclick': 'onNodeDbClick', // 双击
    };
  },
  onNodeDbClick(ev) {
    const node = ev.item;
    const model = node.getModel();
    const { shape } = model;
    if (shape === NODE._STRATEGY) {
      events.eventEmitter.emit(events.OPEN_STRATEGY_NODE, {
        data: {
          ...model,
        },
        actionType: 'detail',
        modelTitle: '策略节点详情',
      });
    } else if (shape === NODE._ACTION) {
      events.eventEmitter.emit(events.OPEN_ACTION_NODE, {
        data: {
          ...model,
        },
        actionType: 'detail',
        modelTitle: '动作节点详情',
      });
    } else if (shape === NODE._CHALLENGE) {
      events.eventEmitter.emit(events.OPEN_CHALLENGE_NODE, {
        data: {
          ...model,
        },
        actionType: 'detail',
        modelTitle: '冠军挑战节点详情',
      });
    }
  },
});
